window.ShareUtil = (function(){
    var _static = {
        shareInfo:null,

        setShareInfo:function(shareInfo){
            this.shareInfo = shareInfo;
        },

        startShare: function ( callback,shareType) {
            if(SystemInfo.getPlatform() != 'weChatGame' && SystemInfo.getPlatform() != 'weChat' && SystemInfo.getPlatform() != 'qqPlay'){
                Log.info("没有分享功能的平台，直接返回成功")
                callback(true);
                return;
            }
            if(!shareType){
                shareType = "default";
            }
            if (SystemInfo.getPlatform() == 'weChatGame'||SystemInfo.getPlatform() == 'weChat') { //微信渠道
                this.shareWX(shareType, callback);
            } else if (SystemInfo.getPlatform() == 'qqPlay') { //QQ渠道
                this.shareQQ(shareType, callback);
            }

        },
        /**
        * 微信分享
        */
        shareWX: function (shareType, callback) {
            //开始分享
            wx.shareAppMessage({
                title: this.shareInfo[shareType].title,
                imageUrl: this.shareInfo[shareType].shareImgUrl,
                query: this.shareInfo[shareType].exetInfo?this.shareInfo[shareType].exetInfo:UserInfo.userId,
                success: function (res) {
                    Log.info("分享成功")
                    callback(true);
                },
                fail: function (res) {
                    Log.info("分享失败")
                    callback(false);
                }
            });
        },


        /**
         * QQ分享
         */
        shareQQ: function (shareType, callback) {//分享内容、图片地址、查询参数、回调
            Log.info('-------------------开始QQ分享')
            BK.Share.share({
                qqImgUrl: this.shareInfo[shareType].shareImgUrl,
                socialPicPath: this.shareInfo[shareType].localImgUrl,
                title: this.shareInfo[shareType].title,
                summary: this.shareInfo[shareType].content,
                extendInfo: this.shareInfo[shareType].exetInfo?this.shareInfo[shareType].exetInfo:UserInfo.userId,
                success: function (succObj) {
                    BK.Console.log('分享成功', succObj.code, JSON.stringify(succObj.data));
                    if(succObj.data.ret==0){
                        callback(true);
                    }else{
                        callback(false);
                    }
                },
                fail: function (failObj) {
                    BK.Console.log('分享失败', failObj.code, JSON.stringify(failObj.msg));
                    callback(false);

                },
                complete: () => {
                    BK.Console.log('分享完成，不论成功失败');
                }
            });
        },

        //显示当前页面的转发按钮
        showShareMenu: function (back) {
            wx.showShareMenu({
                imageUrl: '/res/raw-assets/resources/Texture/zhujiemian.png',
                success: back('success'),
                fail: back('fail'),
            });
        },

        //隐藏当前页面的转发按钮
        hideShareMenu: function (back) {
            wx.hideShareMenu({
                success: back('success'),
                fail: back('fail'),
            });
        },



    }
    return _static;
})();


module.exports = ShareUtil;
